Computers & Internet Logo

Related Topics:

Posted on Mar 21, 2009
Answered by a Fixya Expert

Trustworthy Expert Solutions

At Fixya.com, our trusted experts are meticulously vetted and possess extensive experience in their respective fields. Backed by a community of knowledgeable professionals, our platform ensures that the solutions provided are thoroughly researched and validated.

View Our Top Experts

For the code snippet output of this if code produce if aNumber 3

If (aNumber >= 0)
if (aNumber == 0)System.out.println(''first string'');
else
System.out.println(''second string'');
System.out.println(''third string'');

  • victorina espinosa Mar 21, 2009

    instance variable


    Normal 0 false false false MicrosoftInternetExplorer4
    /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}public class IdentfyMyParts
    {
    public static int x = 7;
    public int y = 3;
    }
    IdentifyMyParts a = new IdentfyMyParts();
    IdentifyMyParts a = new IdentfyMyParts();

    a.y = 5;
    b.y = 6;

    a.x = 1;
    b.x = 2;

    System.out.println(''a.y = ''+ a.y);

    System.out.println(''b.y = ''+ b.y);

    System.out.println(''a.x = ''+ a.x);

    System.out.println(''b.x = ''+ b.x);

    System.out.println(''IdentfyMyParts.x'' +IdentfyMyParts.x);




×

2 Answers

ali_zulfikar

Level 2:

An expert who has achieved level 2 by getting 100 points

MVP:

An expert that got 5 achievements.

Vice President:

An expert whose answer got voted for 100 times.

Governor:

An expert whose answer got voted for 20 times.

  • Expert 156 Answers
  • Posted on Mar 21, 2009
ali_zulfikar
Expert
Level 2:

An expert who has achieved level 2 by getting 100 points

MVP:

An expert that got 5 achievements.

Vice President:

An expert whose answer got voted for 100 times.

Governor:

An expert whose answer got voted for 20 times.

Joined: Nov 04, 2008
Answers
156
Questions
0
Helped
50325
Points
377

There is a bug in this code. The correct code is:-


if (aNumber >= 0)
if (aNumber == 0)
System.out.println(''first string'');
else
System.out.println(''second string'');
else
System.out.println(''third string'');

  • ali_zulfikar
    ali_zulfikar Mar 21, 2009

    There is a bug in this code. The correct code is:-





    if (aNumber >= 0)

    if (aNumber == 0)

    System.out.println(''first string'');

    else

    System.out.println(''second string'');

    else

    System.out.println(''third string'');

×

kuntn93

Level 1:

An expert who has achieved level 1.

  • Contributor 1 Answer
  • Posted on Oct 13, 2012
kuntn93
Contributor
Level 1:

An expert who has achieved level 1.

Joined: Oct 13, 2012
Answers
1
Questions
0
Helped
78
Points
0

If (aNumber >= 0) if (aNumber == 0) System.out.println("first string"); else System.out.println("second string"); System.out.println("third string");

  1. Exercise: What output do you think the code will produce if aNumber is 3?Solution:
    second string third string

Ad

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

0helpful
1answer

How can I format a java string using a width variable?

The Entities in java are slightly different. I adore them being included (finally).

float bigNum = 123456.789012;

String pattern = String.format( "%10.2f is my magic number%n", bigNum);

System.out.println( pattern);

or

System.out.println(

String.format( "%10.3f", bigNum) );

the "decimal place" is the rounding.

lead off with a zero to get leading zeroes

String.format("%03.2f", bigNum));

if I want evenly spaced columns, I have to construct an Object[] array

array[0] = salaryAmt;

array[1] = hourly Rate;

array[2] = "Cowboy Bob";

System.out.println(

"%5.2f,%3.2d,%s%n, array);

Here you will get more information about java string format.

0helpful
1answer

Codes of BufferedReader and FileInputStream in one program

class base
{
int a,b;
void display(int x,int y )
{
a=x;
b=y;
}
void dismax()
{
display();
if(a>b)
System.out.println("first Value is greater"+a);
else
{
}
}
}
class dervd extends base
{
void dismin()
{
display();
if(b>a)
System.out.println("second value is greater"+b);
else
{
}
}
public static void main(String args[])throws IOException
{
BufferedReader in= new BufferedReader (new InputStreamReader(System.in));
System.out.println(" Enter 1st value");
String s=in.readLine();
int m=Integer.parseInt(s);
System.out.println(" Enter 2nd value");
String s1=in.readLine();
int n=Integer.parseInt(s1);

base b1=new base();
b1.display(m,n);
b1.dismax();
dervd d1=new dervd();
d1.dismin();
}
}
0helpful
1answer

The side of the traingle is 4 and the output is * ** *** **** *****

import java.util.*;
public class test {
static Scanner scan = new Scanner(System.in); public static void main(String[] args) {
int mark = scan.nextInt();
for(int i=0; i< mark; i++){ for(int j=0;j<=i;j++) System.out.print("*"); System.out.println(); } } }
4helpful
3answers

A java code for anagram

import java.io.IOException;

public class AnagramApp {
static int size;

static int count;

static char[] charArray;

public static void main(String[] args) throws IOException {
String input = "Java Source and Support";
size = input.length();
count = 0;
charArray = new char[size];
for (int j = 0; j < size; j++)
charArray[j] = input.charAt(j);
doAnagram(size);
}

public static void doAnagram(int newSize) {
int limit;
if (newSize == 1) // if too small, return;
return;
// for each position,
for (int i = 0; i < newSize; i++) {
doAnagram(newSize - 1); // anagram remaining
if (newSize == 2) // if innermost,
display();
rotate(newSize); // rotate word
}
}

// rotate left all chars from position to end
public static void rotate(int newSize) {
int i;
int position = size - newSize;
// save first letter
char temp = charArray[position];
//shift others left
for (i = position + 1; i < size; i++)
charArray[i - 1] = charArray[i];
//put first on right
charArray[i - 1] = temp;
}

public static void display() {
System.out.print(++count + " ");
for (int i = 0; i < size; i++)
System.out.print(charArray[i]);
System.out.println();
}
}
0helpful
1answer

I need a complete workingsource code written in

This is a simple source code for Simple calculator in Java using RMI
//mathServer//
import java.rmi.*;
import java.rmi.Naming.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
import java.util.*;
interface mathInterface extends Remote
{
public int add(int a,int b) throws RemoteException;
public int subt(int a,int b) throws RemoteException;
public int mult(int a,int b) throws RemoteException;
public int div(int a,int b) throws RemoteException;
}
public class mathServer extends UnicastRemoteObject implements
mathInterface
{
public mathServer() throws RemoteException
{
System.out.println("Initializing Server");
}
public int add(int a,int b)
{
return(a+b);
}
public int subt(int a,int b)
{
return(a-b);
}
public int mult(int a,int b)
{
return(a*b);
}
public int div(int a,int b)
{
return(a/b);
}
public static void main(String args[])
{
try
{
mathServer ms=new mathServer();
java.rmi.Naming.rebind("MathServ",ms);
System.out.println("Server Ready");
}
catch(RemoteException RE)
{
System.out.println("Remote Server Error:"+ RE.getMessage());
System.exit(0);
}
catch(MalformedURLException ME)
{
System.out.println("Invalid URL!!");
}
}
}

//mathClient//
import java.rmi.*;
import java.rmi.registry.*;
import java.awt.*;
import java.awt.event.*;
public class mathClient extends Frame implements ActionListener
{
Button B1=new Button("Sum");
Button B2=new Button("Subtract");
Button B3=new Button("Multiply");
Button B4=new Button("Divide");
Label l1=new Label("Number 1");
Label l2=new Label("Number 2");
Label l3=new Label("Result");
TextField t1=new TextField(20);
TextField t2=new TextField(20);
TextField t3=new TextField(20);
public mathClient()
{
super("Calculator");
setLayout(null);
l1.setBounds(20,50,55,25);
add(l1);
l2.setBounds(20,100,55,25);
add(l2);
l3.setBounds(20,150,55,25);
add(l3);
t1.setBounds(150,50,100,25);
add(t1);
t2.setBounds(150,100,100,25);
add(t2);
t3.setBounds(150,150,100,25);
add(t3);
B1.setBounds(20,200,80,25);
add(B1);
B2.setBounds(100,200,80,25);
add(B2);
B3.setBounds(180,200,80,25);
add(B3);
B4.setBounds(260,200,80,25);
add(B4);
B1.addActionListener(this);
B2.addActionListener(this);
B3.addActionListener(this);
B4.addActionListener(this);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public void actionPerformed(ActionEvent AE)
{
if(AE.getSource()==B1)
{
sum();
}
else if(AE.getSource()==B2)
{
subt();
}
else if(AE.getSource()==B3)
{
mult();
}
else if(AE.getSource()==B4)
{
div();
}
}
public void sum()
{
int i=Integer.parseInt(t1.getText());
int j=Integer.parseInt(t2.getText());
int val;
try
{
String ServerURL="MathServ";
mathInterface MI=(mathInterface)Naming.lookup(ServerURL);
val=MI.add(i,j);
t3.setText(""+val);
}
catch(Exception ex)
{
System.out.println("Exception:"+ex);
}
}
public void subt()
{
int i=Integer.parseInt(t1.getText());
int j=Integer.parseInt(t2.getText());
int val;
try
{
String ServerURL="MathServ";
mathInterface MI=(mathInterface)Naming.lookup(ServerURL);
val=MI.subt(i,j);
t3.setText(""+val);
}
catch(Exception ex)
{
System.out.println("Exception:"+ex);
}
}
public void mult()
{
int i=Integer.parseInt(t1.getText());
int j=Integer.parseInt(t2.getText());
int val;
try
{
String ServerURL="MathServ";
mathInterface MI=(mathInterface)Naming.lookup(ServerURL);
val=MI.mult(i,j);
t3.setText(""+val);
}
catch(Exception ex)
{
System.out.println("Exception:"+ex);
}
}
public void div()
{
int i=Integer.parseInt(t1.getText());
int j=Integer.parseInt(t2.getText());
int val;
try
{
String ServerURL="MathServ";
mathInterface MI=(mathInterface)Naming.lookup(ServerURL);
val=MI.div(i,j);
t3.setText(""+val);
}
catch(Exception ex)
{
System.out.println("Exception:"+ex);
}
}
public static void main(String args[])
{
mathClient MC=new mathClient();
MC.setVisible(true);
MC.setSize(600,500);
};
}
4helpful
1answer

Design a Menu-driven interactive programme to find out all the Capital cities of India using switch statement

import java.io.*;
public class capital
{
public static void main(String args[]) throws Exception
{
System.out.println("Enter 1 for Andra Pradesh");
System.out.println("Enter 2 for Arunachal Pradesh.");
System.out.println("Enter 3 for Assam.");
System.out.println("Enter 4 for Bihar.");
System.out.println("Enter 5 for Chhattisgarh.");
System.out.println("Enter 6 for Goa.");
System.out.println("Enter 7 for Karnataka.");
System.out.println("Enter 8 for Gujrat.");
System.out.println("Enter 9 for Haryana.");
System.out.println("Enter 10 for Himachal Pradesh.");
System.out.println("Enter 11 for Mizoram.");
System.out.println("Enter 12 for Jammu & Kashmir.");
System.out.println("Enter 13 for Jharkhand.");
System.out.println("Enter 14 for Kerala.");
System.out.println("Enter 15 for Madhya Pradesh.");
System.out.println("Enter 16 for Maharashtra.");
System.out.println("Enter 17 for Manipur.");
System.out.println("Enter 18 for Meghalaya.");
System.out.println("Enter 19 for Nagaland.");
System.out.println("Enter 20 for Orissa.");
System.out.println("Enter 21 for Punjab.");
System.out.println("Enter 22 for Rajasthan.");
System.out.println("Enter 23 for Sikkim.");
System.out.println("Enter 24 for Tamil Nadu.");
System.out.println("Enter 25 for Tripura.");
System.out.println("Enter 26 for Uttar Pradesh.");
System.out.println("Enter 27 for Uttaranchal.");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String read = br.readLine();
int ch = Integer.parseInt(read);

switch(ch)
{
case 1: System.out.println("Hyderabad");
break;
case 2: System.out.println("Itanager");
break;
case 3: System.out.println("Dispur");
break;
case 4: System.out.println("Patna");
break;
case 5: System.out.println("Raipur");
break;
case 6: System.out.println("Panaji");
break;
case 7: System.out.println("Bangalore");
break;
case 8: System.out.println("Gandhinagar");
break;
case 9: System.out.println("Chandigarh");
break;
case 10: System.out.println("Shimla");
break;
case 11: System.out.println("Aizawl");
break;
case 12: System.out.println("Srinagar(Summer) & Jammu(Winter)");
break;
case 13: System.out.println("Ranchi");
break;
case 14: System.out.println("Trivandrum");
break;
case 15: System.out.println("Bhopal");
break;
case 16: System.out.println("Bombay");
break;
case 17: System.out.println("Imphal");
break;
case 18: System.out.println("Shillong");
break;
case 19: System.out.println("Kohima");
break;
case 20: System.out.println("Bhubaneswar");
break;
case 21: System.out.println("chandigarh");
break;
case 22: System.out.println("Jaipur");
break;
case 23: System.out.println("Gangtok");
break;
case 24: System.out.println("Chennai");
break;
case 25: System.out.println("Agartala");
break;
case 26: System.out.println("Lucknow");
break;
case 27: System.out.println("Dehra Dun");
break;
default: System.out.println("Invalid entry!");
break;
}
}
}

(IGNOU - BCA - CS-74 - Q.4 - 2009)
Visit : Www.hamidraza.page.tl
0helpful
1answer

Code for method parseInt() in java

parseInt(java.lang.String, int)

This code takes two arguments, a string constructor from the Java language and an integer. Its purpose is to parse (meaning de-construct or disassemble into component parts) one data type into another.

Here is an example of a Java program to specify and print out the dimensions of a rectangle, taken from the page http://www.roseindia.net/java/beginners/entervaluesfromkeyboard.shtml:

class Rectangle{
int length, breadth;
void show(int x, int y){
length = x;
breadth = y;
}
int calculate(){
return(length * breadth);
}
}
public class EnterValuesFromKeyboard{
public static void main(String[] args) {
Rectangle rectangle = new Rectangle();
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
rectangle.show(a, b);
System.out.println(" you have entered these values : " + a + " and " + b);
int area = rectangle.calculate();
System.out.println(" area of a rectange is : " + area);
}
}
2helpful
2answers

Rename a folder in c drive using java code

import java.io.*;

public class RenameFileOrDir{

public static void main(String[] args) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Please enter the file or directory
name which has to be Renamed : ");

String old_name = in.readLine();
File oldfile = new File(old_name);


if(!oldfile.exists())
{

System.out.println("File or directory does not exist.");

System.exit(0);

}

System.out.print("please enter the new file or directory name : ");

String new_name = in.readLine();

File newfile = new File(new_name);

System.out.println("Old File or directory name : "+ oldfile);
System.out.println("New File or directory name : "+ newfile);
boolean Rename = oldfile.renameTo(newfile);

if(!Rename)
{

System.out.println("File or directory does not rename successfully.");

System.exit(0);

}

else {

System.out.println("File or directory rename is successfully.");

}

}

}
0helpful
1answer

Table creation via textfields using swings

import java.lang.Object;
import javax.swing.table.DefaultTableModel;


public class tabletest extends javax.swing.JFrame {
String[][] row = null;
String[] title=new String[3];
private int i;


/** Creates new form tabletest */
public tabletest() {
initComponents();
setTitle("table test");
setVisible(true);
System.out.print("NO Database Needed");
title[0]="Name";
title[1]="Desig";
title[2]="id";
}


/*
" In middle of this two source one generated code will be there that will be done by dragging ur fields to ur frame. THIS IS FOR netbeans IDE "
*/

private void b1ActionPerformed(java.awt.event.ActionEvent evt) {
row=new String[4][3];
// TODO add your handling code here:

String s1=t1.getText();
System.out.println(" event 1");
String s2=t2.getText();
System.out.println(" event 2");
int k=Integer.parseInt(t3.getText());
String s3=""+k;
System.out.println(" event 3");
try{
// for(int i=0;i<=2;i++)
row[i][0]=s1;
row[i][1]=s2;
row[i][2]=s3;
i++;

}catch(Exception e){
e.printStackTrace();

}
table.setModel(new DefaultTableModel(row,title));
}

private void b2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

t1.setText("");
t2.setText("");
t3.setText("");

}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new tabletest().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton b1;
private javax.swing.JButton b2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel l1;
private javax.swing.JLabel l2;
private javax.swing.JLabel l3;
private javax.swing.JPanel p2;
private javax.swing.JScrollPane scp1;
private javax.swing.JTextField t1;
private javax.swing.JTextField t2;
private javax.swing.JTextField t3;
private javax.swing.JTable table;
// End of variables declaration

}
Not finding what you are looking for?

88 views

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Grand Canyon Tech
Grand Canyon Tech

Level 3 Expert

3867 Answers

Brad Brown

Level 3 Expert

19187 Answers

Cindy Wells

Level 3 Expert

6688 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...