Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By stealthghost

java programing help!! (SHIFTING)


This discussion is about "java programing help!! (SHIFTING)" in the "Programming" forums.
kani unta akong program kay mu shift ug string by 2 meaning ang "abcde" i-shift by 2 kay "cdefg" pero akong problema lahi ang output ...

  1. #1
    Newbie
    Join Date
    Jul 2012
    Gender
    Male
    Posts
    6

    Default java programing help!! (SHIFTING)


    kani unta akong program kay mu shift ug string by 2
    meaning ang "abcde" i-shift by 2 kay "cdefg"
    pero akong problema lahi ang output nga iyang ipagawas gud

    Code:
    public class shifting {
    
        public static String shift(String in) {
            char[] temp = new char[in.length()];
            int[] temp2 = new int[in.length()];
            for(int i=0;i<in.length();i++){
                temp[i] = in.charAt(i);
                temp2[i] = (int) (temp[i])+2;
                temp[i] = (char) (temp2[i]);
            }
            return temp.toString();
        }
    
    
        public static void main(String[] args) {
            String str = "abcde";
            System.out.println(shift(str));
        }
    }
    nya kani iyang output kun i-run ni nimo siya using the above code

    Code:
    output: [C@3e25a5
    please help!!!

  2. #2
    C.I.A. stealthghost's Avatar
    Join Date
    Oct 2005
    Gender
    Male
    Posts
    4,292
    Blog Entries
    1

    Default Re: java programing help!! (SHIFTING)

    Kung ingon ana ang gawas means naka array ang data..
    What you need to do is to parse and add it to a container
    string using for loop or for each method..

  3. #3
    Junior Member mr.green's Avatar
    Join Date
    Oct 2008
    Gender
    Male
    Posts
    106

    Default Re: java programing help!! (SHIFTING)

    you need to change your return data type sa imo method. array of chars or string then from main you will make a container of string of array para mudwat sa ge return sa imo method.

  4. #4
    Elite Member
    Join Date
    May 2011
    Gender
    Male
    Posts
    1,466

    Default Re: java programing help!! (SHIFTING)

    sakto c boss stealthghost ts. isud sa string. try daw ni ako gihimo
    Code:
    public class Shifting {
        
        public static String Process( String input ) {
            char a [] = input.toCharArray();
            char shifted [] = new char [ a.length ];
            for( int x = 2; x < a.length; x++ )shifted [ x - 2  ] = a [ x ];
            for( int x = shifted.length - 2; x < shifted.length; x++ ){
                int val = ( int ) shifted [ x - 2 ] + 2;
                shifted [ x ] = ( char ) val;
            }
            return new String( shifted );
        }
        
        public static void main( String args [] ){
            System.out.println( Process("abcde"));
        }
    }

    OT: ang problema ani ang katong thread nakong usa wa pa na solve.
    Last edited by jairoh_; 08-19-2012 at 05:05 PM.

  5. #5
    Newbie
    Join Date
    Jul 2012
    Gender
    Male
    Posts
    6

    Default Re: java programing help!! (SHIFTING)

    sir unsaon pag himo ug container string? naintriga lang ko gud
    hehe beginner paman gud ta ani
    btw ok na siya kay akong gi change iyang return value type.. nya sakto iyang output kun i print lang dayun siya

  6. #6
    Newbie
    Join Date
    Jul 2012
    Gender
    Male
    Posts
    6

    Default Re: java programing help!! (SHIFTING)

    Quote Originally Posted by jairoh_ View Post
    sakto c boss stealthghost ts. isud sa string. try daw ni ako gihimo
    Code:
    public class Shifting {
        
        public static String Process( String input ) {
            char a [] = input.toCharArray();
            char shifted [] = new char [ a.length ];
            for( int x = 2; x < a.length; x++ )shifted [ x - 2  ] = a [ x ];
            for( int x = shifted.length - 2; x < shifted.length; x++ ){
                int val = ( int ) shifted [ x - 2 ] + 2;
                shifted [ x ] = ( char ) val;
            }
            return new String( shifted );
        }
        
        public static void main( String args [] ){
            System.out.println( Process("abcde"));
        }
    }

    OT: ang problema ani ang katong thread nakong usa wa pa na solve.
    ako pang i try na sir.. thanks
    na solve na sir.. hehe kani lang akong gi gamit nga code

    Code:
    public class shift{
        public static char[] shift(String in) {
            char[] temp = in.toCharArray();
            char[] temp2 = new char[in.length()];
            for(int i=0;i<in.length();i++)
            	temp2[i] =(char) (temp[i]+2);
            return temp2;
        }
    
    
        public static void main(String[] args) {
            String str = "abcde";
            System.out.println(shift(str));
        }
    }

  7. #7
    C.I.A. stealthghost's Avatar
    Join Date
    Oct 2005
    Gender
    Male
    Posts
    4,292
    Blog Entries
    1

    Default Re: java programing help!! (SHIFTING)

    Quote Originally Posted by deathkorn View Post
    sir unsaon pag himo ug container string? naintriga lang ko gud
    hehe beginner paman gud ta ani
    btw ok na siya kay akong gi change iyang return value type.. nya sakto iyang output kun i print lang dayun siya
    Additional info for you ts,

    Ako pasabut sa container string, didto nimo i.form ang characters into words 1 by 1 tungod kay naka array pa ka..

    Ang itsura sa usa ka array, based sa example nimu is like this..
    'c', 'd', 'e', 'f', 'g', etc...

    So, maghimo ka og loop nga i.butang sa string object ang imu characters aron mahimong string data.
    Example:
    String s = "my string";
    s += " append string";

    Mahimo na siya, "my string append string"

    Same principle applies sa integer.. Aron makuha nimo ang total value or even at double or float.

    I hope you get my point. Good day.
    deathkorn likes this.

  8. #8
    Newbie
    Join Date
    Jul 2012
    Gender
    Male
    Posts
    6

    Default Re: java programing help!! (SHIFTING)

    Quote Originally Posted by stealthghost View Post
    Additional info for you ts,

    Ako pasabut sa container string, didto nimo i.form ang characters into words 1 by 1 tungod kay naka array pa ka..

    Ang itsura sa usa ka array, based sa example nimu is like this..
    'c', 'd', 'e', 'f', 'g', etc...

    So, maghimo ka og loop nga i.butang sa string object ang imu characters aron mahimong string data.
    Example:
    String s = "my string";
    s += " append string";

    Mahimo na siya, "my string append string"

    Same principle applies sa integer.. Aron makuha nimo ang total value or even at double or float.

    I hope you get my point. Good day.
    naka gets ko sir.. thanks

  9.    Advertisement

Similar Threads

 
  1. help sa java programing
    By xianz87 in forum Programming
    Replies: 5
    Last Post: 10-10-2010, 09:49 PM
  2. need help in java programming: creating a folder
    By rastaman81 in forum Programming
    Replies: 4
    Last Post: 03-11-2009, 08:51 AM
  3. Need help in Installing Java programs in my Samsung D880
    By Soj in forum Software & Games (Old)
    Replies: 0
    Last Post: 04-24-2008, 06:34 PM
  4. Java programming help pls...
    By mr_gwen in forum Programming
    Replies: 6
    Last Post: 11-03-2006, 12:30 AM
  5. nid help..java programming
    By ronninalpha in forum Programming
    Replies: 3
    Last Post: 09-13-2006, 07:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top