Question about Sun Java Studio Standard 5 (SSJI9501TL9M) for PC, , Linux

3 Answers

Jawa void how i can solve the problem of java void (o) i m new in computer so pl solution should be simple

Posted by on

  • kannan1995 May 11, 2010

    I WANT TO KNOW THE QUESTION APPROPRIATELY?

  • Anonymous Mar 15, 2014

    // Victoria Andrews
    // Exercise 4.19
    import java.util.Scanner;



    public class SalesTest
    {

    static int count = 1;

    public static void main (String [] args) // main method
    {
    Scanner ST = new Scanner(System.in);

    int item; // number of item sold
    System.out.println(" We will now calculate weekly pay for employess!");

    System.out.printf( "Enter amount sold of item number %d (or -1 to QUIT):", count );
    item = ST.nextInt();// Enter number of item sold
    int sales = 0;
    count++;
    while( item != -1 && count!=5)
    {
    sales += getValue( item );
    System.out.printf( "Enter amount sold of item number %d (or -1 to QUIT):", count );
    item = ST.nextInt();// Enter number of item sold
    count++;
    }
    // Calculate pay
    double pay = (0.09 * sales) + 200.00 ;
    System.out.printf("The employees week pay is %.02f\n", pay);
    }
    // getValue method
    // Accepts an int (item) as an argument
    // Returns the corresponding value of the item
    public static double getValue( int i )
    {
    switch( i )
    {
    case 1:
    return 239.99;
    case 2:
    return 129.75;
    case 3:
    return 99.95;
    default:
    return 350.89;
    }
    }
    }

×

3 Answers

  • Level 1:

    An expert who has achieved level 1.

    Corporal:

    An expert that has over 10 points.

    Problem Solver:

    An expert who has answered 5 questions.

  • Contributor
  • 11 Answers

Void means your not returning any values in the method
public void add(int a,int b){
}
If method has return values which means your returning some values to the called of the method

public int add(int a,int b){
{
return a+b;
}

Posted on Jan 01, 2015

  • Level 1:

    An expert who has achieved level 1.

    Mayor:

    An expert whose answer got voted for 2 times.

  • Contributor
  • 4 Answers

Try this code to see the difference between void() and none void
1) public void getString(){
System.out.print("This is outputed from within the function");
}
2public String getstring(){
String str="This is outputed at the end of the function";
return str;
}

Posted on Jan 22, 2009

  • Level 1:

    An expert who has achieved level 1.

    Hot-Shot:

    An expert who has answered 20 questions.

    Corporal:

    An expert that has over 10 points.

    Mayor:

    An expert whose answer got voted for 2 times.

  • Contributor
  • 35 Answers

You should not use arguments in void function in java ... in java pertaining to void the compiler doesn't understand the arguments and treats that as invalid... in c it is ok

Posted on Oct 02, 2008

1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

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

×

Loading...
Loading...

Related Questions:

1 Answer

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(); } } }

Dec 04, 2010 | Sun Java Programming Language (cdj-275)

3 Answers

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();
}
}

Nov 22, 2010 | Computers & Internet

1 Answer

Code for a simple banking system.


//My name is rajeshwari and i have posted u a simple Bank program
import java.awt.*;
import java.awt.event.*;
public class MyBank implements ActionListener,ItemListener
{
Frame f1;
CheckboxGroup cg1;
Checkbox ch1,ch2,ch3,ch4,ch5,ch6;
Label l1,l2,l3,l4,l5;
TextField t1,t2,t3,t4;
Button b1,b2,b3;
Font ft;

MyBank()
{
f1 = new Frame("My Bank");
f1.setBounds(50,50,500,500);
f1.setLayout(null);

cg1 = new CheckboxGroup();
ch1 = new Checkbox("Short term[1yr]",cg1,false);
ch1.setBounds(50,50,120,30);
ch1.addItemListener(this);
ch2 = new Checkbox("Medium term[2yrs]",cg1,false);
ch2.setBounds(50,100,120,30);
ch2.addItemListener(this);
ch3 = new Checkbox("Long term[5yrs]",cg1,false);
ch3.setBounds(50,150,120,30);
ch3.addItemListener(this);
ch4 = new Checkbox("Very long term[10yrs]",cg1,false);
ch4.setBounds(50,200,120,30);
ch4.addItemListener(this);

l1 = new Label("Rate of Interest");
l1.setBounds(210,50,150,30);
t1 = new TextField();
t1.setBounds(360,50,100,30);
l2 = new Label("Deposit Amount");
l2.setBounds(210,125,150,30);
t2 = new TextField();
t2.setBounds(360,125,100,30);
l3 = new Label("Interest Amount");
l3.setBounds(210,200,150,30);
t3 = new TextField();
t3.setBounds(360,200,100,30);
l4 = new Label("Maturity Amount");
l4.setBounds(210,275,150,30);
t4 = new TextField();
t4.setBounds(360,275,100,30);

ch5 = new Checkbox("Senior Citizens");
ch5.setBounds(125,320,100,30);
ch5.addItemListener(this);
ch6 = new Checkbox("NRI");
ch6.setBounds(275,320,100,30);
ch6.addItemListener(this);

l5 = new Label("Extra : 0.5 Rate of Interest on Sr.Citizens and 1 Rate of Interest on NRI");
l5.setBounds(50,370,400,30);

b1 = new Button("Calc");
b1.setBounds(125,440,50,30);
b1.addActionListener(this);
b2 = new Button("Clear");
b2.setBounds(225,440,50,30);
b2.addActionListener(this);
b3 = new Button("Exit");
b3.setBounds(325,440,50,30);
b3.addActionListener(this);

f1.addWindowListener(new mywin());
ft=new Font("Arial",Font.ITALIC,20);
f1.add(ch1);
f1.add(ch2);
f1.add(ch3);
f1.add(ch4);
f1.add(l1);
f1.add(t1);
f1.add(l2);
f1.add(t2);
f1.add(l3);
f1.add(t3);
f1.add(l4);
f1.add(t4);
f1.add(ch5);
f1.add(ch6);
f1.add(l5);
f1.add(b1);
f1.add(b2);
f1.add(b3);
f1.setVisible(true);
}
public class mywin extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
}
public void itemStateChanged(ItemEvent ie)
{
double r;

try{
if(ch1.getState() == true)
{
t1.setText("3.5");
}
else if(ch2.getState() == true)
{
t1.setText("4");
}
else if(ch3.getState() == true)
{
t1.setText("4.5");
}
else if(ch4.getState() == true)
{
t1.setText("5");
}

if(ch5.getState() == true)
{
r = 0.5 + Double.parseDouble(t1.getText());
t1.setText(r+"");
}

if(ch6.getState() == true)
{
r = 1 + Double.parseDouble(t1.getText());
t1.setText(r+"");
}
}catch(Exception e){
System.out.println(e);
}
}

public void actionPerformed(ActionEvent ae)
{
double ri,damt,in,mamt;
if(ae.getSource() == b1)
{
ri = Double.parseDouble(t1.getText());
damt = Double.parseDouble(t2.getText());

in = (damt * ri) / 100;
mamt = damt + in;

t3.setText(in+"");
t4.setText(mamt+"");
}
else if(ae.getSource() == b2)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
ch5.setState(false);
ch6.setState(false);
}
else if(ae.getSource() == b3)
{
System.exit(0);
}
}
public static void main(String args[])
{
MyBank obj = new MyBank();
}
}

Nov 13, 2010 | Sun Java Programming Language (cdj-275)

1 Answer

How to get no. Of pixels from given image through java


try this code

import java.awt.image.PixelGrabber;
import java.awt.Toolkit;
import java.awt.Image;
class getpixel2
{
public static void main(String args[]) throws Exception
{

Image image = Toolkit.getDefaultToolkit().getImage("D:\\one.jpg");

if(image==null)
System.out.println("NO FIle");
PixelGrabber grabber = new PixelGrabber(image, 0, 0, -1, -1, false);

if (grabber.grabPixels())
{
int width = grabber.getWidth();
int height = grabber.getHeight();

if (isGreyscaleImage(grabber))
{
byte[] data = (byte[]) grabber.getPixels();

}
else
{
int[] data = (int[]) grabber.getPixels();
for(int i=0;i<data.length;i++)
{
int r = (data[i] >> 16) & 0xff;
int g = (data[i] >> 8) & 0xff;
int b = (data[i] >> 0) & 0xff;
System.out.println("(R,G,B)=("r","g","b")");
}
}

}
}
public static final boolean isGreyscaleImage(PixelGrabber pg)
{
return pg.getPixels() instanceof byte[];
}
} import java.awt.image.PixelGrabber;
import java.awt.Toolkit;
import java.awt.Image;
class getpixel2
{
public static void main(String args[]) throws Exception
{

Image image = Toolkit.getDefaultToolkit().getImage("D:\\one.jpg");

if(image==null)
System.out.println("NO FIle");
PixelGrabber grabber = new PixelGrabber(image, 0, 0, -1, -1, false);

if (grabber.grabPixels())
{
int width = grabber.getWidth();
int height = grabber.getHeight();

if (isGreyscaleImage(grabber))
{
byte[] data = (byte[]) grabber.getPixels();

}
else
{
int[] data = (int[]) grabber.getPixels();
for(int i=0;i<data.length;i++)
{
int r = (data[i] >> 16) & 0xff;
int g = (data[i] >> 8) & 0xff;
int b = (data[i] >> 0) & 0xff;
System.out.println("(R,G,B)=("r","g","b")");
}
}

}
}
public static final boolean isGreyscaleImage(PixelGrabber pg)
{
return pg.getPixels() instanceof byte[];
}
}

May 15, 2010 | Computers & Internet

1 Answer

How to convert infix to postfix using stacks in java programming?


u can try the follwing coding
import java.io.*;
import java.util.*;
//begin coding for the stack interface
interface Stack<E>
{
public boolean isEmpty();//tests is current stack is empty. Returns true if so, and false if not.
public E top() throws StackException;//retrieves value at the top of the stack. Stack cannot be empty.
public void push(E value) throws StackException;//pushes a value on the top of the stack.
public void pop() throws StackException;//removes a value from the top of the stack. Stack cannot be empty.
}//terminates coding of Stack interface

//begin coding for the objArrayStack class
class objArrayStack<E> implements Stack<E>
{
//constructor
public objArrayStack()
{
topValue=-1;
}//terminates constructor
public void push(E value)throws StackException
{
if(topValue<ArraySize-1)//currrent stack is not full
{
++topValue;
Info[topValue]=value;
}//terminates if
else //current stack is full
throw new StackException("Error: Overflow");
}//terminates push method
public void pop() throws StackException
{
if(!isEmpty())//current stack is not empty
--topValue;
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates pop method
public boolean isEmpty()
{
return topValue==-1;
}//terminates isEmpty method
public E top() throws StackException
{
if(!isEmpty())//stack is not empty
return (E)Info[topValue];
else //stack is empty
throw new StackException("Error: Underflow");
}//terminates top method
//declare instance variables
final int ArraySize=10;
private Object Info[]=new Object[ArraySize];
private int topValue;

//begins coding for the StackException class
class StackException extends RuntimeException
{
//constructor
public StackException(String str)
{
super(str);
}//terminates text of constructor
}//terminates text of StackException class

//method to convert from infix to postfix notation
public static String InToPost(String infixString)
{
//operator stack initialized
objArrayStack<Character> operatorStack = new objArrayStack<Character>();
//postfix string initialized as empty
String postfixString = " ";
//scan infix string and take appropriate action
for(int index = 0; index < infixString.length(); ++index)
{
char chValue = infixString.charAt(index);
if(chValue == '(')
operatorStack.push('(');
else if(chValue == ')')
{
Character oper = operatorStack.top();
while(!(oper.equals('(')) && !(operatorStack.isEmpty()))
{
postfixString += oper.charValue();
operatorStack.pop();
oper = operatorStack.top();
}//end while loop
operatorStack.pop();
}//end else if
else if(chValue == '+' || chValue == '-')
{
if(operatorStack.isEmpty()) //operatorStack is empty
operatorStack.push(chValue);
else //current operatorStack is not empty
{
Character oper = operatorStack.top();
while(!(operatorStack.isEmpty() || oper.equals(new Character('(')) || oper.equals(new Character(')'))))
{
operatorStack.pop();
postfixString += oper.charValue();
}//ends while loop
operatorStack.push(chValue);
}//end else
}//end else if
else if(chValue == '*' || chValue == '/')
{
if(operatorStack.isEmpty())
operatorStack.push(chValue);
else
{
Character oper = operatorStack.top();
while(!oper.equals(new Character('+')) && !oper.equals(new Character('-')) && !operatorStack.isEmpty())
{
operatorStack.pop();
postfixString += oper.charValue();
}//end while loop
operatorStack.push(chValue);
}//end else
}//end else if
else
postfixString += chValue;
}//end for loop
while(!operatorStack.isEmpty())
{
Character oper = operatorStack.top();
if(!oper.equals(new Character('(')))
{
operatorStack.pop();
postfixString += oper.charValue();
}//end if
}//end while
return postfixString ;
}//terminates text of InToPost method

public static void main(String[]args)
{
objArrayStack mystack = new objArrayStack();
System.out.println("Enter a string");
Scanner scan = new Scanner(System.in);
scan.nextLine();
String str = scan.nextLine();
InToPost(str);
}//terminates text of main method
}//terminates text of objArrayStack class

Mar 16, 2010 | Sun Java Programming Language (cdj-275)

1 Answer

I want to read text file which is located in c drive using java code can anybody help me out


import java.io.*;
import java.util.Scanner;

public final class ReadWithScanner { public static void main(String... aArgs) throws FileNotFoundException {
ReadWithScanner parser = new ReadWithScanner("C:\\Temp\\test.txt");
parser.processLineByLine();
log("Done.");
}

/**
* @param aFileName full name of an existing, readable file.
*/

public ReadWithScanner(String aFileName){
fFile = new File(aFileName);
}

/** Template method that calls {@link #processLine(String)}. */
public final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(fFile);
try {
//first use a Scanner to get each line
while ( scanner.hasNextLine() ){
processLine( scanner.nextLine() );
}
}
finally {
//ensure the underlying stream is always closed
scanner.close();
}
}

/**
* Overridable method for processing lines in different ways.
*
* <P>This simple default implementation expects simple name-value pairs, separated by an
* '=' sign. Examples of valid input :
* <tt>height = 167cm</tt>
* <tt>mass = 65kg</tt>
* <tt>disposition = "grumpy"</tt>
* <tt>this is the name = this is the value</tt>
*/

protected void processLine(String aLine){
//use a second Scanner to parse the content of each line
Scanner scanner = new Scanner(aLine);
scanner.useDelimiter("=");
if ( scanner.hasNext() ){
String name = scanner.next();
String value = scanner.next();
log("Name is : " + quote(name.trim()) + ", and Value is : " + quote(value.trim()) );
}
else {
log("Empty or invalid line. Unable to process.");
}
//(no need for finally here, since String is source)
scanner.close();
}

// PRIVATE //
private final File fFile;

private static void log(Object aObject){
System.out.println(String.valueOf(aObject));
}

private String quote(String aText){
String QUOTE = "'";
return QUOTE + aText + QUOTE;
}
}

Jun 22, 2009 | Sun Java Programming Language (cdj-275)

1 Answer

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);
}
}

Apr 09, 2009 | Sun Java Programming Language (cdj-275)

2 Answers

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.");

}

}

}

Mar 30, 2009 | Sun Java Programming Language (cdj-275)

1 Answer

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

}

Mar 13, 2009 | Computers & Internet

1 Answer

Student library record







Import java.awt;
Import java.applet;
class Book extends Applet
{ String book name="Handbook";
int Book no=50;
int d.o.s=” ”;}
Type ur required body content here.
}
public static void main(String args[])

{
}

/*<applet code=”book” height=500 width=500 ></applet>
this appears to go beyond the scope of troubleshooting



















Sep 27, 2008 | ArcMedia JavaScript Source Code 3000 Pro...

Not finding what you are looking for?
Sun Java Studio Standard 5 (SSJI9501TL9M) for PC, , Linux Logo

Related Topics:

456 people viewed this question

Ask a Question

Usually answered in minutes!

Top Sun Computers & Internet Experts

Les Dickinson
Les Dickinson

Level 3 Expert

18333 Answers

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

Cosma Papouis
Cosma Papouis

Level 3 Expert

404 Answers

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

Answer questions

Manuals & User Guides

Loading...