The Artima Developer Community
Sponsored Link

Java Answers Forum
java code

2 replies on 1 page. Most recent reply: Sep 2, 2010 10:55 PM by Nishant Ranjan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
bhavna raghuvanshi

Posts: 6
Nickname: bhavna13
Registered: Jun, 2010

java code Posted: Jun 14, 2010 12:15 AM
Reply to this message Reply
Advertisement
i need a code in java to write a function that takes a value from the user and returns the value divided by 2.pls help....


Code Obsessed

Posts: 1
Nickname: coder1
Registered: Jul, 2010

Re: java code Posted: Jul 6, 2010 8:15 AM
Reply to this message Reply
How about this:

int weight = 180;
int weight2 = 160;
int totalWeight = 0;

totalWeight = weight + weight2;

System.out.println( "The average weight is " + (totalWeight / 2));

Nishant Ranjan

Posts: 1
Nickname: nranjan
Registered: Sep, 2010

Re: java code Posted: Sep 2, 2010 10:55 PM
Reply to this message Reply
public class Scanf {

/**
* C - Style scanf function
* @param args
*/
public static void main(String[] args) {
//Auto-generated method stub
System.out.println("Enter as many numbers and press enter :");

String input = null;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try {
input = in.readLine();

} catch (IOException e) {
//Auto-generated catch block
e.printStackTrace();
}
String[] numString = input.split(" ");

int sum=0;
for(String s:numString)
sum+=Integer.valueOf(s);

System.out.println("Sum of nos: " + sum);
}


}

Flat View: This topic has 2 replies on 1 page
Topic: Not sure why I have to press enter to get results Previous Topic   Next Topic Topic: HTTP Redirect in java servlets -- critical scenario given..

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use