Java Forum

 Forum:   Subject:  View:  

 

 Blue Pelican Site
 Login/Edit Account


 Forgot your password?

 

     (Page 4 of 5)
<Prv  1  2  3  4 5  Nxt>  

Topic: How to do the Array of Hope Lab
ID: Smitty Date/Time: 12/01/2010 9:05:07 AM
Message:
My students and I are having trouble figuring out this lab can anyone please show me their code?
Reply Title: This code works:  
ID: Benjamin Date/Time: 02/17/2014 6:59:51 PM
Message:

import java.io.*;
import java.util.*;
public class adder
{
   public static void main(String args[])
   {
      Scanner kbr= new Scanner(System.in);
      
      System.out.println("Enter the numbers to be added in a format like: 2 - 4 + 45");
      String input= kbr.nextLine();
      
     // The portion below removes all spaces from the input line. It works like to the email spam detecter on 17-5 and 17-6.
      Scanner prime= new Scanner(input);
      prime.useDelimiter("");
      String s= "";
             while (prime.hasNext())
      {
       while (prime.hasNext("\\s"))  // finds and skips all the spaces.
        {
             prime.skip("\\s*");
             
        }
       if (prime.hasNext())
        {
           s= s+ prime.next();
        

Topic: Project 11 - Name Reversal
ID: Panda Date/Time: 01/27/2011 6:26:14 AM
Message:
Does anyone know how to do this?
Reply Title: i think this is it  
ID: JavaCode Date/Time: 02/11/2011 10:54:55 AM
Message:
import java.io.*;
import java.util.*;
public class Project
{
   public static void main(String args[])
   {
       System.out.print("Please enter your name: ");
       Scanner Levi=new Scanner(System.in);
       String name=Levi.nextLine(),newname;
       int x=name.length(),b;
       for(b=x-1;b>=0;b--)
       {
       
          newname=name.substring(b,b+1);
          System.out.print(newname.toLowerCase());
       }
   }
}
   
\\ I believe this is the code
Reply Title: This one works  
ID: Zane Date/Time: 02/04/2014 9:16:01 AM
Message:
import java.io.*;
import java.util.*;
public class NameReversal
{
 public static void main( String args[] )
 {
   Scanner kbReader = new Scanner(System.in);
   System.out.print("What's your name? ");
   String name = kbReader.nextLine();
   int strLen = name.length();
   String reversedName= "";
   for(int j = strLen - 1; j >= 0; j--)
   {  
    String letter = name.substring(j, j + 1); //picks up just one letter at a time
    reversedName = reversedName + letter;
   }
   System.out.println(reversedName.toLowerCase());
 }
}

Topic: Project 17- Add em up
ID: JavaCode Date/Time: 02/11/2011 11:00:14 AM
Message:
My partner and I are having problems creating this project (Project 17- Add 'em Up), if somebody could please post their code or fix ours, so we can study how it works, that would be nice! :)
Reply Title: This is what we have so far  
ID: JavaCode Date/Time: 02/11/2011 11:03:17 AM
Message:
This is what we have so far:
We can do things like 907+5, or 907-5, but we cant get 907+5-10 (both a + and -)
import java.io.*;
import java.util.*;
public class Modded
{
   public static void main(String args[])
   {
       Scanner kb=new Scanner(System.in);
       System.out.print("Enter something like 8 + 33 + 1,345 - 137 : ");
       String s=kb.nextLine();
       Scanner sc=new Scanner(s);
       int sum=0;
       if (s.contains("+"))
       {
       sc.useDelimiter("\\s*\\+\\s*");
       while(sc.hasNextInt())
       {
       sum=sum+sc.nextInt();
       }
   }
     if (s.contains("-"))
     {
     sc.useDelimiter("\\s*\\-\\s*");
     while(sc.hasNextInt())
     {
     sum=sc.nextInt()-sc.nextInt();
     }
   }
   System.out.println("Sum is: "+sum);
   }}

Topic: Lesson 17-2
ID: angie Date/Time: 02/28/2011 11:40:56 PM
Message:
while i'm doing project 17-2, i got error("missing return statement") and i don't know how to fix it
my code is
public class Crypto
{
  public String encrypt(String sntnc)
  {
      String finalSntnc = "";
      
      for(int j = 0; j < sntnc.length( ); j++)
      {
          char nextChar = sntnc.charAt(j);
          switch (nextChar)
          {
              case 'v':
              case 'V':
              {
                  finalSntnc = finalSntnc + "ag\',r";
                  break;
              }
              
              case 'm':
              case 'M':
              {
                  finalSntnc = finalSntnc +"saad";
                  break;
              }
        case 'g':
              case 'G':
              {                       finalSntnc = finalSntnc + "jeb..w";
                  break;
              }
              
              case 'b':
              case 'B':
              {
                  finalSntnc = finalSntnc + "dug>?/";
                  break;
              }
              
              default:
              {
                  finalSntnc = finalSntnc + nextChar;
              }
          }
          return finalSntnc;
  
  }
}

public String decrypt(String sntnc)
{
  sntnc = sntnc.replace("ag\',r","v");
  sntnc = sntnc.replace("saad", "m");
  sntnc = sntnc.replace("jeb..w", "g");
  sntnc = sntnc.replace("dug>?/", "b");
  return sntnc;

}
}

Topic: Accessing the super classvariable/method
ID: manu Date/Time: 01/06/2012 7:03:41 AM
Message:
i have a code like this
class A{
 int i=10;
}
class B extends A {
 int i=20;
}
class C extends B {
int i=30;
}
How to access the A class version of i  from Class C




Topic: Help with Project(Hard!)
ID: Java Lean Date/Time: 09/04/2012 5:36:44 PM
Message:
* This is project 17 and it asks to create a code that uses delimiters/while loops to add or subtract numbers, but I have no idea how to code that! I used the s.contains("-") and s.contains("+") in two if statements with while loops in them, but it wouldn't work. Please tell me the best way to code where an addition and subtraction sign will work!

Topic: for-Loop
ID: Java Rules Date/Time: 12/06/2012 10:58:45 AM
Message:
Can someone please explain step-by-step this for-Loop problem?

double kk = 3;
int j = 0;
for(j = 0; j <= 100; j++) {
    kk = kk + Math.pow(j,2);
    ++kk;
}
System.out.println(j);

The answer should be 101. Thanks.

Topic: Nested for-Loop
ID: Java Rules Date/Time: 12/06/2012 11:07:44 AM
Message:
Can someone please explain step-by-step this problem?

int j, k;
int count = 0;
for(j=0; j<4; j++)
{
     for(k=0; k<10; k++)
     {
            count++;
     }
}
System.out.print(count--);
System.out.println(count);

The answer is 4039. Thanks.
  << New message thread

(Page 4 of 5)             <<PrevPage   1   2   3   4   5   NextPage>>  

This Forum automated by software from bluepelicanjava.com